﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 易容酒店管理系统
{
    public partial class Reception : Form
    {
        public Reception()
        {
            InitializeComponent();
        }

        
        private void Reception_Load(object sender, EventArgs e)
        {
            ADD();
            Method.frm.button1.Visible = true;
            Method.frm.button2.Visible = true;
            Method.frm.button3.Visible = true;
            Method.frm.button4.Visible = true;
            Method.frm.button5.Visible = true;
        }
        /// <summary>
        /// 获取所有客房信息
        /// </summary>
        private void ADD()
        {
            listView1.Items.Clear();
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from Guest_Room_Number";
            SqlDataAdapter add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            add.Fill(set, "Guest_Room_Number");
            DataTable table = set.Tables["Guest_Room_Number"];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow drow = table.Rows[i];
                ListViewItem lvi = new ListViewItem(drow["PrimaryID"].ToString());
                lvi.SubItems.Add(drow["PrimaryID"].ToString());
                lvi.SubItems.Add(drow["ID"].ToString());
                lvi.SubItems.Add(drow["RoomID"].ToString());
                lvi.SubItems.Add(drow["Type"].ToString());
                lvi.SubItems.Add(drow["Guest_information"].ToString());
                lvi.SubItems.Add(drow["Telephone"].ToString());
                lvi.SubItems.Add(drow["Guest_room_InTim"].ToString());
                lvi.SubItems.Add(drow["Guest_room_OutTim"].ToString());
                lvi.SubItems.Add(drow["Day"].ToString());
                lvi.SubItems.Add(drow["Money"].ToString());
                listView1.Items.Add(lvi);
            }
        }
        //获取已入住的客房
        private void LookNotNull(string Type)
        {
            listView1.Items.Clear();
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from Guest_Room_Number where Type='" + Type + "' and Occupancy='有';";
            SqlDataAdapter add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            add.Fill(set, "Guest_Room_Number");
            DataTable table = set.Tables["Guest_Room_Number"];

            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow drow = table.Rows[i];
                ListViewItem lvi = new ListViewItem(drow["ID"].ToString());
                lvi.SubItems.Add(drow["Type"].ToString());
                lvi.SubItems.Add(drow["Occupancy"].ToString());
                lvi.SubItems.Add(drow["Guest_information"].ToString());
                lvi.SubItems.Add(drow["Telephone"].ToString());
                lvi.SubItems.Add(drow["Guest_room_status"].ToString());
                listView1.Items.Add(lvi);
            }
        }
        //获取未入住的客房
        private void Look(string p)
        {
            listView1.Items.Clear();
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from Guest_Room_Number where Type='" + p + "' and Occupancy='无';";
            SqlDataAdapter add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            add.Fill(set, "Guest_Room_Number");
            DataTable table = set.Tables["Guest_Room_Number"];

            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow drow = table.Rows[i];
                ListViewItem lvi = new ListViewItem(drow["ID"].ToString());
                lvi.SubItems.Add(drow["Type"].ToString());
                lvi.SubItems.Add(drow["Occupancy"].ToString());
                lvi.SubItems.Add(drow["Guest_information"].ToString());
                lvi.SubItems.Add(drow["Telephone"].ToString());
                lvi.SubItems.Add(drow["Guest_room_status"].ToString());
                listView1.Items.Add(lvi);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
                ADD();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
